/*------------------------------------------------------------------------------
 
Project: Mathisen, R.M., Schakel, W., Hense, S., Elsässer, L., Persson, M. and
	Pontusson, J. (forthcoming). 'Unequal Responsiveness and Government
	Partisanship in Northwest Europe,' in Lupu, N. and Pontusson, J. (eds)
	Unequal Democracies: Public Policy, Responsiveness, and Redistribution in an
	Era of Rising Economic Inequality. Cambridge: Cambridge University Press.

Note: This do-file constructs the figures presented in the main text and
	supplementary appendix.

Data: mshepp_data (see mshepp_01_prep do-file for original sources)

	DS1_v2_1, data on the U.S., downloaded in June 2021 from https://www.russell
	sage.org/datasets/economic-inequality-and-political-representation (note:
	only used for Figures 1 and A1)

Last updated: 5 May 2023

Sections (note that the Figures are presented out of order, because Figures 1
	and A1 are preceded by the same set of commands):
	1. Figure 1: Bivariate associations
	2. Figure A1: Effect of support on policy, accounting for preference overlap
	3. Figure 2: Effect of P90-P10 and P90-P50 gaps
	4. Figure 3: Coalition analysis
	5. Figure 4: Partisanship interactions, P90-P50
	6. Figure 5: Partisanship interactions, P90-P50, economic issues only
	7. Figure 6: Partisanship interactions over time, P90-P50
	8. Figure A2: Partisanship interactions over time, P90-P10

------------------------------------------------------------------------------*/

* This is where the pooled dataset is stored
global mshepp_data "YOUR/PATH/HERE"

* This is where the data on the United States are stored
global data_orig "YOUR/PATH/HERE"

/*------------------------------------------------------------------------------
 1. Figure 1: Bivariate associations
------------------------------------------------------------------------------*/

* As mentioned above, U.S. data is used for Figure 1 and Figure A1. We add this
* data here.
use "$data_orig/DS1_v2_1.dta", clear

rename *, lower
gen c = 5
drop if outcome == 2.5 | outcome == 3.5 | outcome > 4
recode outcome (2/4 = 1), gen(polchange4)
recode outcome (2 = 1) (3 4 = 0), gen(polchange2)
rename pred*0_sw p*0
gen diff9050 = p90 - p50
gen diff5010 = p50 - p10
keep c year p10 p50 p90 diff* polchange*

tempfile data_us
save `data_us'

use "$mshepp_data/mshepp_data.dta", clear
append using `data_us'

* Now we can make the Figure
matrix coef = J(18, 2, .)
local counter = 1

forval i = 10(40)90 {
	reg polchange2 p`i' i.c [pw = weight], vce(robust)
	matrix m`i' = r(table)
	matrix coef[`counter', 1] = m`i'[1, 1]
	matrix coef[`counter', 2] = m`i'[2, 1]

	forval c = 1/5 {
		reg polchange2 p`i' if c == `c', vce(robust)
		matrix m`i'`c' = r(table)
		matrix coef[`=`counter'+1', 1] = m`i'`c'[1, 1]
		matrix coef[`=`counter'+1', 2] = m`i'`c'[2, 1]
		local ++counter
	}
	local ++counter
}

svmat coef

* Confidence intervals
gen lci = coef1 - 1.96 * coef2
gen hci = coef1 + 1.96 * coef2

* The "x" variable determines the order of the countries on the x-axis
matrix x = [1\11\15\19\23\5\ 2\12\16\20\24\6\ 3\13\17\21\25\7]
matrix inc = [1\1\1\1\1\1\ 2\2\2\2\2\2\ 3\3\3\3\3\3]
svmat x
svmat inc

twoway bar coef1 x if inc == 1, col(gs14) fi(100) msiz(medlarge) ||			///
	bar coef1 x if inc == 2, col(gs11) fi(100) m(diamond) ||				///
	bar coef1 x if inc == 3, col(gs7) fi(100) m(square) ||					///
	rspike lci hci x if inc == 1, lc(gs0) lw(thin) ||						///
	rspike lci hci x if inc == 2, lc(gs0) lw(thin) ||						///
	rspike lci hci x if inc == 3, lc(gs0) lw(thin)							///
	xlab(2 "DE+NL+NO+SE" 6 "US" 12 "DE" 16 "NL" 20 "NO" 24 "SE")			///
	ylab(-.5(.25).75, ang(hor) glc(gs15)) yline(0, lc(gs0) lw(thin))		///
	xtitle("") ytitle(Effect of support on policy) xsize(6.5)				///
	leg(order(1 "P10" 2 "P50" 3 "P90") row(1) symx(8) lw(thin) lc(gs0))		///
	plotr(m(3 3 0 0)) graphr(lc(white) col(white) m(2 4 3 3)) scale(1.1)

drop coef1-inc1

/*------------------------------------------------------------------------------
 2. Figure A1: Effect of support on policy, accounting for preference overlap
------------------------------------------------------------------------------*/

* Again, the U.S. data should be added before producing this Figure

matrix coef10 = J(6, 1, .)
matrix coef50 = J(6, 1, .)
matrix coef90 = J(6, 1, .)

reg polchange2 p50 diff9050 diff5010 i.c if c != 5 [pw = weight], vce(robust)
matrix m0 = r(table)
matrix coef10[1, 1] = m0[1, 1] - m0[1, 3]
matrix coef50[1, 1] = m0[1, 1]
matrix coef90[1, 1] = m0[1, 1] + m0[1, 2]

local counter = 1

forval c = 1/5 {
	reg polchange2 p50 diff9050 diff5010 if c == `c', vce(robust)
	matrix m`c' = r(table)
	matrix coef10[`=`counter'+1', 1] = m`c'[1, 1] - m`c'[1, 3]
	matrix coef50[`=`counter'+1', 1] = m`c'[1, 1]
	matrix coef90[`=`counter'+1', 1] = m`c'[1, 1] + m`c'[1, 2]
	local ++counter
}

matrix coef = coef10 \ coef50 \ coef90
svmat coef

* The "x" variable determines the order of the countries on the x-axis
matrix x = [1\11\15\19\23\5\ 2\12\16\20\24\6\ 3\13\17\21\25\7]
matrix inc = [1\1\1\1\1\1\ 2\2\2\2\2\2\ 3\3\3\3\3\3]
svmat x
svmat inc

twoway bar coef1 x if inc == 1, col(gs14) fi(100) msiz(medlarge) ||			///
	bar coef1 x if inc == 2, col(gs11) fi(100) m(diamond) ||				///
	bar coef1 x if inc == 3, col(gs7) fi(100) m(square)						///
	xlab(2 "DE+NL+NO+SE" 6 "US" 12 "DE" 16 "NL" 20 "NO" 24 "SE")			///
	ylab(-.5(.5)2, ang(hor) glc(gs15) gmax) yline(0, lc(gs0) lw(thin))		///
	ytitle(Independent effect of support on policy, m(0 1.5 0 0))			///
	leg(order(1 "P10" 2 "P50" 3 "P90") row(1) symx(8))						///
	plotr(m(3 3 0 0)) graphr(lc(white) col(white) m(2 4 3 3))				///
	scale(1.1) xtitle("") xsize(6.5)

drop if c == 5
drop coef1-x

/*------------------------------------------------------------------------------
 3. Figure 2: Effect of P90-P10 and P90-P50 gaps
------------------------------------------------------------------------------*/

* For the rest of the Figures, we only use the main dataset, which we load here
use "$mshepp_data/mshepp_data.dta", clear

* We use the 'grc1leg' ado-file for several Figures, including this one. If this
* is not installed, you can search for it by typing 'findit grc1leg'.

quietly foreach v of varlist diff9010 diff9050 diff5010 {
	reg polchange2 `v' p50 i.c [pw = weight], vce(robust)
	margins, at(`v' = (-.3(.01).3)) atmeans post
	matrix c`v'0 = r(table)'
	svmat c`v'0
	drop c`v'02-c`v'04 c`v'07-c`v'09
	
	forval c = 1/4 {
		reg polchange2 `v' p50 if c == `c', vce(robust)
		margins, at(`v' = (-.3(.01).3)) atmeans post
		matrix m`v'`c' = e(b)'
		}

	matrix c`v' = [m`v'1, m`v'2, m`v'3, m`v'4]
	svmat c`v'
}

range x -.3 .3 61

* Each figure contains the range of 95% of observations
twoway rarea cdiff901005 cdiff901006 x if x<.27 & x>-.27, col(gs14) fi(100)	///
	|| line cdiff901001 x if x<.27 & x>-.27, lw(medthick) lc(gs0) || line	///
	cdiff90101 x if x<.27 & x>-.27, lw(medthick) lc(gs0) lp(longdash) ||	///
	line cdiff90102 x if x<.27 & x>-.27, lw(medthick) lc(gs0) lp(shortdash)	///
	|| line cdiff90103 x if x<.27 & x>-.27, lw(medthick) lc(gs11)			///
	lp(longdash) || line cdiff90104 x if x<.27 & x>-.27, lw(medthick)		///
	lc(gs11) lp(shortdash) xlab(-.2(.1).2) ylab(0(.2)1, ang(hor) glc(gs15))	///
	xtitle(P90 - P10 preferences, m(0 0 0 2))								///
	ytitle(Probability of policy change, m(0 0 0 0))						///
	legend(order(3 "Germany" 5 "Norway" 2 "Pooled" 4 "Netherlands"			///
	6 "Sweden") col(3) symx(8)) scale(1.3)									///
	plotr(m(2 2 1 3)) graphr(lc(white) col(white) m(0 0 0 0))				///
	name(f2a, replace) nodraw

twoway rarea cdiff905005 cdiff905006 x if x<.22 & x>-.22, col(gs14) fi(100)	///
	|| line cdiff905001 x if x<.22 & x>-.22, lw(medthick) lc(gs0) || line	///
	cdiff90501 x if x<.22 & x>-.22, lw(medthick) lc(gs0) lp(longdash) ||	///
	line cdiff90502 x if x<.22 & x>-.22, lw(medthick) lc(gs0) lp(shortdash) ///
	|| line cdiff90503 x if x<.22 & x>-.22, lw(medthick) lc(gs11)			///
	lp(longdash) || line cdiff90504 x if x<.22 & x>-.22, lw(medthick)		///
	lc(gs11) lp(shortdash) xlab(-.2(.1).2) ylab(0(.2)1, ang(hor) glc(gs15))	///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	legend(order(3 "Germany" 5 "Norway" 2 "Pooled" 4 "Netherlands"			///
	6 "Sweden") col(3) symx(8)) scale(1.3)									///
	plotr(m(7 7 1 3)) graphr(lc(white) col(white) m(5 0 0 0))				///
	name(f2b, replace) nodraw

* Change X-size to 7 in the graph editor (the grc1leg ado-file ignores size
* commands)
grc1leg f2a f2b, col(2) graphr(lc(white) col(white)) ycommon

drop cdiff901001-x

/*------------------------------------------------------------------------------
 4. Figure 3: Coalition analysis
------------------------------------------------------------------------------*/

matrix coef = J(6, 2, .)
local counter = 1

forval i = 10(40)90 {
	foreach v in 9050 5010 {
		reg polchange2 p`i' i.c if coal`v' == 1 [pw = weight_coal], vce(robust)
		matrix m`i'`v' = r(table)
		matrix coef[`counter', 1] = m`i'`v'[1, 1]
		matrix coef[`counter', 2] = m`i'`v'[2, 1]
		local ++counter
	}
}

svmat coef
gen lci = coef1 - 1.96 * coef2 // confidence intervals can be adjusted here
gen hci = coef1 + 1.96 * coef2 // confidence intervals can be adjusted here

matrix x = [1\5\2\6\3\7]
matrix inc = [1\1\2\2\3\3]
svmat x
svmat inc

twoway bar coef1 x if inc == 1, col(gs14) fi(100) ||						///
	bar coef1 x if inc == 2, col(gs11) fi(100) ||							///
	bar coef1 x if inc == 3, col(gs7) fi(100) ||							///
	rspike lci hci x, lc(gs0) yline(0, lc(gs0) lw(thin))					///
	xtitle("") ytitle(Effect of support on policy) xlab(none)				///
	ylab(-1(.5)1, ang(hor) glc(gs15))										///
	leg(order(1 "P10" 2 "P50" 3 "P90") row(1)								///
	symx(8)) plotr(m(3 3 0 0)) graphr(lc(white) col(white) m(4 4 2 9))		///
	text(1.1 2 "P50 and P90 align", size(medlarge) m(0 0 2 0))				///
	text(1.1 6 "P10 and P50 align", size(medlarge) m(0 0 2 0))				///
	scale(1.1) xsize(6)

drop coef1-inc1

/*------------------------------------------------------------------------------
 5. Figure 4: Partisanship interactions, P90-P50
------------------------------------------------------------------------------*/

quietly forval l = 0/1 {
	reg polchange2 c.diff9050##c.leftgov2 p50 i.c [pw = weight], vce(robust)
	margins, at(diff9050 = (-.19(.01).19) leftgov2 = (`l')) atmeans post
	matrix coef`l' = r(table)'
	svmat coef`l'
	drop coef`l'2-coef`l'4 coef`l'7-coef`l'9

	forval c = 1/4 {
		reg polchange2 c.diff9050##c.leftgov2 p50 if c == `c', vce(robust)
		margins, at(diff9050 = (-.19(.01).19) leftgov2 = (`l')) atmeans post
		matrix m`l'`c' = e(b)'
	}
}

* Replacing the Netherlands (maximum value = .5, see text for details)
reg polchange2 c.diff9050##c.leftgov2 p50 if c == 2, vce(robust)
quietly margins, at(diff9050 = (-.19(.01).19) leftgov2 = (.5)) atmeans post
matrix m12 = e(b)'

matrix coef = [m01, m11, m02, m12, m03, m13, m04, m14]
svmat coef

range x -.19 .19 39

twoway rarea coef05 coef06 x, col(gs14) fi(100) ||							///
	line coef01 x, lw(medthick) lc(gs0) ||									///
	line coef1 x, lw(medthick) lc(gs0) lp(longdash) ||						///
	line coef3 x, lw(medthick) lc(gs0) lp(shortdash) ||						///
	line coef5 x, lw(medthick) lc(gs11) lp(longdash) ||						///
	line coef7 x, lw(medthick) lc(gs11) lp(shortdash)						///
	xlab(-.2(.1).2) ylab(0(.2)1, ang(hor) glc(gs15))						///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	ytitle(Probability of policy change, m(0 0 0 0))						///
	legend(order(3 "Germany" 5 "Norway" 2 "Pooled" 4 "Netherlands"			///
	6 "Sweden") col(3) symx(8)) scale(1.3)									///
	plotr(m(0 0 1 3)) graphr(lc(white) col(white) m(0 1.5 0 2))				///
	title(No left government, col(gs0) m(0 0 2 0)) name(f4a, replace) nodraw

twoway rarea coef15 coef16 x, col(gs14) fi(100) ||							///
	line coef11 x, lw(medthick) lc(gs0) ||									///
	line coef2 x, lw(medthick) lc(gs0) lp(longdash) ||						///
	line coef4 x, lw(medthick) lc(gs0) lp(shortdash) ||						///
	line coef6 x, lw(medthick) lc(gs11) lp(longdash) ||						///
	line coef8 x, lw(medthick) lc(gs11) lp(shortdash)						///
	xlab(-.2(.1).2) ylab(0(.2)1, ang(hor) glc(gs15))						///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	legend(order(3 "Germany" 5 "Norway" 2 "Pooled" 4 "Netherlands"			///
	6 "Sweden") col(3) symx(8)) scale(1.3)									///
	plotr(m(0 0 1 3)) graphr(lc(white) col(white) m(5 1.5 0 2))				///
	title(Maximum left government, col(gs0) m(0 0 2 0)) name(f4b, replace)	///
	nodraw

* Change X-size to 7
grc1leg f4a f4b, graphr(lc(white) col(white)) graphr(m(2 2 2 0)) ycommon

drop coef01-x

/*------------------------------------------------------------------------------
 6. Figure 5: Partisanship interactions, P90-P50, economic issues only
------------------------------------------------------------------------------*/

quietly forval l = 0/1 {
	reg polchange2 c.diff9050##c.leftgov2 p50 i.c if dim == 1				///
	[pw = weight], vce(robust)
	margins, at(diff9050 = (-.19(.01).19) leftgov2 = (`l')) atmeans post
	matrix coef`l' = r(table)'
	svmat coef`l'
	drop coef`l'2-coef`l'4 coef`l'7-coef`l'9

	forval c = 1/4 {
		reg polchange2 c.diff9050##c.leftgov2 p50 if c == `c' & dim == 1,	///
		vce(robust)
		margins, at(diff9050 = (-.19(.01).19) leftgov2 = (`l')) atmeans post
		matrix m`l'`c' = e(b)'
	}
}

* Replacing the Netherlands (maximum value = .5, see text for details)
reg polchange2 c.diff9050##c.leftgov2 p50 if c == 2 & dim == 1, vce(robust)
quietly margins, at(diff9050 = (-.19(.01).19) leftgov2 = (.5)) atmeans post
matrix m12 = e(b)'

matrix coef = [m01, m11, m02, m12, m03, m13, m04, m14]
svmat coef

range x -.19 .19 39

twoway rarea coef05 coef06 x, col(gs14) fi(100) ||							///
	line coef01 x, lw(medthick) lc(gs0) ||									///
	line coef1 x, lw(medthick) lc(gs0) lp(longdash) ||						///
	line coef3 x, lw(medthick) lc(gs0) lp(shortdash) ||						///
	line coef5 x, lw(medthick) lc(gs11) lp(longdash) ||						///
	line coef7 x, lw(medthick) lc(gs11) lp(shortdash)						///
	xlab(-.2(.1).2) ylab(0(.2)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	ytitle(Probability of policy change, m(0 0 0 0))						///
	legend(order(3 "Germany" 5 "Norway" 2 "Pooled" 4 "Netherlands"			///
	6 "Sweden") col(3) symx(8)) scale(1.3)									///
	plotr(m(0 0 1 3)) graphr(lc(white) col(white) m(0 1.5 0 2))				///
	title(No left government, col(gs0) m(0 0 2 0)) name(f5a, replace) nodraw

twoway rarea coef15 coef16 x, col(gs14) fi(100) ||							///
	line coef11 x, lw(medthick) lc(gs0) ||									///
	line coef2 x, lw(medthick) lc(gs4) lp(longdash) ||						///
	line coef4 x, lw(medthick) lc(gs4) lp(shortdash) ||						///
	line coef6 x, lw(medthick) lc(gs11) lp(longdash) ||						///
	line coef8 x, lw(medthick) lc(gs11) lp(shortdash)						///
	xlab(-.2(.1).2) ylab(0(.2)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	legend(order(3 "Germany" 5 "Norway" 2 "Pooled" 4 "Netherlands"			///
	6 "Sweden") col(3) symx(8)) scale(1.3)									///
	plotr(m(0 0 1 3)) graphr(lc(white) col(white) m(5 1.5 0 2))				///
	title(Maximum left government, col(gs0) m(0 0 2 0)) name(f5b, replace)	///
	nodraw

* Change X-size to 7
grc1leg f5a f5b, graphr(lc(white) col(white)) graphr(m(2 2 2 0)) ycommon

drop coef01-x

/*------------------------------------------------------------------------------
 7. Figure 6: Partisanship interactions over time, P90-P50
------------------------------------------------------------------------------*/

/* Note that Stata 16 or later is required to properly display this graph, as it
uses transparency. To approximate the look of the final Figure in Stata 15 or
earlier, you can turn off the transparency by deleting "%50" in "col(gs12%50)"
for all the subgraphs. */

quietly forval l = 0/1 { // looping over partisanship
	forval d = 1/2 { // looping over dimensions
		forval t = 0/1 { // looping over time periods
			reg polchange2 c.diff9050##c.leftgov2 p50 i.c					///
			if dim == `d' & post97 == `t' [pw = weight_dim], vce(robust)
			margins, at(diff9050 = (-.19(.01).19) leftgov2 = (`l')) atmeans post
			matrix coef`l'`d'`t' = r(table)'
			svmat coef`l'`d'`t'
			drop coef`l'`d'`t'2-coef`l'`d'`t'4 coef`l'`d'`t'7-coef`l'`d'`t'9
		}
	}
}

* Clarifying which predictions are which (note that *_1, *_5 and *_6 denote the
* point estimates and lower and upper confidence interval bounds, respectively)
rename coef0* ri* // left
rename coef1* le* // right
rename ri1* ri_ec* // economic
rename ri2* ri_ot* // other
rename le1* le_ec* // economic
rename le2* le_ot* // other
rename *_ec0* *_ec_pre* // 1960-1997
rename *_ot0* *_ot_pre* // 1960-1997
rename *_ec1* *_ec_post* // 1998-2016
rename *_ot1* *_ot_post* // 1998-2016

range x -.19 .19 39

* Economic issues, 1960-1997
twoway rarea ri_ec_pre5 ri_ec_pre6 x, col(gs12%50) lw(none) fi(100) || 		///
	rarea le_ec_pre5 le_ec_pre6 x, col(gs12%50) lw(none) fi(100) ||			///
	line ri_ec_pre1 x, lc(gs0) lp(dash) lw(medthick) || 					///
	line le_ec_pre1 x, lc(gs0) lp(solid) lw(medthick)						///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	ytitle(Probability of policy change, m(0 1 0 0))						///
	legend(order(3 "No left goverment" 4 "Maximum left government")			///
	symx(5) symy(5) siz(small)) title(1960-1997, siz(medlarge) col(gs0))	///
	plotr(m(0 0 3 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(f6a, replace) nodraw

* Economic issues, 1998-2016
twoway rarea ri_ec_post5 ri_ec_post6 x, col(gs12%50) lw(none) fi(100) || 	///
	rarea le_ec_post5 le_ec_post6 x, col(gs12%50) lw(none) fi(100) || 		///
	line ri_ec_post1 x, lc(gs0) lp(dash) lw(medthick) || 					///
	line le_ec_post1 x, lc(gs0) lp(solid) lw(medthick)						///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	title(1998-2016, siz(medlarge) col(gs0))								///
	plotr(m(0 0 3 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(f6b, replace) nodraw

* Other issues, 1960-1997
twoway rarea ri_ot_pre5 ri_ot_pre6 x, col(gs12%50) lw(none) fi(100) || 		///
	rarea le_ot_pre5 le_ot_pre6 x, col(gs12%50) lw(none) fi(100) || 		///
	line ri_ot_pre1 x, lc(gs0) lp(dash) lw(medthick) || 					///
	line le_ot_pre1 x, lc(gs0) lp(solid) lw(medthick)						///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	ytitle(Probability of policy change, m(0 1 0 0))						///
	title(1960-1997, siz(medlarge) col(gs0))								///
	plotr(m(0 0 0 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(f6c, replace) nodraw

* Other issues, 1998-2016
twoway rarea ri_ot_post5 ri_ot_post6 x, col(gs12%50) lw(none) fi(100) || 	///
	rarea le_ot_post5 le_ot_post6 x, col(gs12%50) lw(none) fi(100) || 		///
	line ri_ot_post1 x, lc(gs0) lp(dash) lw(medthick) || 					///
	line le_ot_post1 x, lc(gs0) lp(solid) lw(medthick)						///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P50 preferences, m(0 0 0 2))								///
	title(1998-2016, siz(medlarge) col(gs0))								///
	plotr(m(0 0 0 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(f6d, replace) nodraw

* The following two graphs are not yet the final product, but we can't
* add the 'nodraw' option here, so they are displayed anyway
grc1leg f6a f6b, graphr(lc(white) col(white)) graphr(m(2 2 2 0)) ycommon	///
	title(Economic / welfare issues, col(gs0)) name(f6ab, replace)

grc1leg f6c f6d, graphr(lc(white) col(white)) graphr(m(2 2 2 0)) ycommon	///
	title(Other issues, col(gs0)) name(f6cd, replace)

* Change Y-size and X-size to 8 in the graph editor
grc1leg f6ab f6cd, row(2) graphr(lc(white) col(white)) graphr(m(2 2 2 0))	///
	ycommon

drop ri_ec_pre1-x

/*------------------------------------------------------------------------------
 8. Figure A2: Partisanship interactions over time, P90-P10
------------------------------------------------------------------------------*/

/* Note that Stata 16 or later is required to properly display this graph, as it
uses transparency. To approximate the look of the final Figure in Stata 15 or
earlier, you can turn off the transparency by deleting "%50" in "col(gs12%50)"
for all the subgraphs. */

quietly forval l = 0/1 { // looping over partisanship
	forval d = 1/2 { // looping over dimensions
		forval t = 0/1 { // looping over time periods
			reg polchange2 c.diff9010##c.leftgov2 p50 i.c					///
			if dim == `d' & post97 == `t' [pw = weight_dim], vce(robust)
			margins, at(diff9010 = (-.19(.01).19) leftgov2 = (`l')) atmeans post
			matrix coef`l'`d'`t' = r(table)'
			svmat coef`l'`d'`t'
			drop coef`l'`d'`t'2-coef`l'`d'`t'4 coef`l'`d'`t'7-coef`l'`d'`t'9
		}
	}
}

* Clarifying which predictions are which (note that *_1, *_5 and *_6 denote the
* point estimates and lower and upper confidence interval bounds, respectively)
rename coef0* ri* // left
rename coef1* le* // right
rename ri1* ri_ec* // economic
rename ri2* ri_ot* // other
rename le1* le_ec* // economic
rename le2* le_ot* // other
rename *_ec0* *_ec_pre* // 1960-1997
rename *_ot0* *_ot_pre* // 1960-1997
rename *_ec1* *_ec_post* // 1998-2016
rename *_ot1* *_ot_post* // 1998-2016

range x -.19 .19 39

* Economic issues, 1960-1997
twoway rarea ri_ec_pre5 ri_ec_pre6 x, col(gs12%50) lw(none) fi(100) || 		///
	rarea le_ec_pre5 le_ec_pre6 x, col(gs12%50) lw(none) fi(100) || 		///
	line ri_ec_pre1 x, lw(medium) lc(gs0) lp(dash) lw(medthick) || 			///
	line le_ec_pre1 x, lw(medium) lc(gs0) lp(solid) lw(medthick)			///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P10 preferences, m(0 0 0 2))								///
	ytitle(Probability of policy change, m(0 1 0 0))						///
	legend(order(3 "No left goverment" 4 "Maximum left government")			///
	symx(5) symy(5) siz(small)) title(1960-1997, siz(medlarge) col(gs0))	///
	plotr(m(0 0 0 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(fa2a, replace) nodraw

* Economic issues, 1998-2016
twoway rarea ri_ec_post5 ri_ec_post6 x, col(gs12%50) lw(none) fi(100) || 	///
	rarea le_ec_post5 le_ec_post6 x, col(gs12%50) lw(none) fi(100) || 		///
	line ri_ec_post1 x, lw(medium) lc(gs0) lp(dash) lw(medthick) || 		///
	line le_ec_post1 x, lw(medium) lc(gs0) lp(solid) lw(medthick)			///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P10 preferences, m(0 0 0 2))								///
	title(1998-2016, siz(medlarge) col(gs0))								///
	plotr(m(0 0 0 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(fa2b, replace) nodraw

* Other issues, 1960-1997
twoway rarea ri_ot_pre5 ri_ot_pre6 x, col(gs12%50) lw(none) fi(100) || 		///
	rarea le_ot_pre5 le_ot_pre6 x, col(gs12%50) lw(none) fi(100) || 		///
	line ri_ot_pre1 x, lw(medium) lc(gs0) lp(dash) lw(medthick) || 			///
	line le_ot_pre1 x, lw(medium) lc(gs0) lp(solid) lw(medthick)			///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P10 preferences, m(0 0 0 2))								///
	ytitle(Probability of policy change, m(0 1 0 0))						///
	title(1960-1997, siz(medlarge) col(gs0))								///
	plotr(m(0 0 4 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(fa2c, replace) nodraw

* Other issues, 1998-2016
twoway rarea ri_ot_post5 ri_ot_post6 x, col(gs12%50) lw(none) fi(100) || 	///
	rarea le_ot_post5 le_ot_post6 x, col(gs12%50) lw(none) fi(100) || 		///
	line ri_ot_post1 x, lw(medium) lc(gs0) lp(dash) lw(medthick) || 		///
	line le_ot_post1 x, lw(medium) lc(gs0) lp(solid) lw(medthick)			///
	xlab(-.2(.1).2) ylab(0(.5)1, ang(hor) glc(gs15) gmax)					///
	xtitle(P90 - P10 preferences, m(0 0 0 2))								///
	title(1998-2016, siz(medlarge) col(gs0))								///
	plotr(m(0 0 4 4)) graphr(lc(white) col(white))							///
	scale(1.3) name(fa2d, replace) nodraw

* The following two graphs are not yet the final product, but we can't
* add the 'nodraw' option here, so they are displayed anyway
grc1leg fa2a fa2b, graphr(lc(white) col(white)) graphr(m(2 2 2 0)) ycommon	///
	title(Economic / welfare issues, col(gs0)) name(fa2ab, replace)

grc1leg fa2c fa2d, graphr(lc(white) col(white)) graphr(m(2 2 2 0)) ycommon	///
	title(Other issues, col(gs0)) name(fa2cd, replace)

* Change Y-size and X-size to 8 in the graph editor
grc1leg fa2ab fa2cd, row(2) graphr(lc(white) col(white)) graphr(m(2 2 2 0))	///
	ycommon

drop ri_ec_pre1-x
